package ccpvspiral1;

import static org.junit.Assert.*;

import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;

import ccpvspiral1.FileManager.Action;

public class TestFileManager {

	@Before
	public void setUp() throws Exception {
	}

	@After
	public void tearDown() throws Exception {
	}

	//@Test
	public void testFindCommandList() {
		BufferedReader buff;
		System.out.println("testing1");
		try {
			buff = new BufferedReader(new FileReader("/home/robert/workspace/ccpv/CCPV spiral 1/data/test.txt"));
			
			System.out.println("File opened.");
			
			try {
				Action act = null;
				HashMap<FileManager.COMMAND,String> actions = FileManager.findCommandList(buff);
				int counter = 0;
				for (FileManager.COMMAND cmd : actions.keySet()) {
					String val = actions.get(cmd);
					System.out.println(counter + ": " + cmd + " => "+ val);
					counter++;
				}
			} catch (IllegalArgumentException e) {
				// TODO Auto-generated catch block
				System.out.println("Bad formatting of input file");
				e.printStackTrace();
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}

		} catch (FileNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}		
		
	}
	
	//@Test
	public void testFindNextCommand() {
		System.out.println("testing2");
		BufferedReader buff;
		
			try {
				buff = new BufferedReader(new FileReader("/home/robert/workspace/ccpv/CCPV spiral 1/data/test.txt"));
				
				System.out.println("File opened.");
				
				try {
					Action act = null;
					while ((act = FileManager.findNextCommand(buff)) != null){
						  System.out.println(act.command + " => " + act.value);
					}
				} catch (IllegalArgumentException e) {
					// TODO Auto-generated catch block
					System.out.println("Bad formatting of input file");
					e.printStackTrace();
				} catch (IOException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}

			} catch (FileNotFoundException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}		
	}

	@Test
	public void testCsvReader() {
		System.out.println("testing csv");
			FileManager.csvReader("/home/robert/workspace/ccpv/CCPV spiral 1/data/format.txt");
	}

}
